<template>
<div class="login-container">
  <div class="shadow"></div>
  <div class="videoContainer">
      <video class="fullscreenVideo" id="bgVid" playsinline="" autoplay="" muted="" loop="">
        <source src="@/assets/video.3cf57b17.mp4" type="video/mp4">
      </video>
    </div>
    <div class="login-box">
      <div class="avatar-box">
        <img src="@/assets/logo1.33ef7fa0.png" />
      </div>
      <!-- 登录表单区域 -->
      <el-form
        ref="form"
        label-width="0px"
        class="login-form"
        :model="form"
        :rules="rules"
      >
        <el-form-item prop="account">
          <el-input v-model="form.account" prefix-icon="el-icon-user-solid" />
        </el-form-item>

        <el-form-item prop="password">
          <el-input
            v-model="form.password"
            prefix-icon="el-icon-lock"
            type="password"
            show-password
          />
        </el-form-item>

        <el-form-item prop="yanzhengma">
          <el-input
            v-model="form.code"
            prefix-icon="el-icon-lock"
            placeholder="验证码"
          >
          <template slot="append"><img @click="updataCode" :src="'https://slwl-geteway.itheima.net/manager/captcha?key='+form.key+'&0='+form.key" alt=""></template>
        </el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="danger" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { login, getCode } from '@/api/user.js'
export default {
  name: 'index-page',
  data () {
    return {
      form: {
        account: 'shenlingadmin',
        code: '',
        key: String(new Date().getTime()),
        password: '123456'

      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          {
            min: 3,
            max: 15,
            message: '长度在 3 到 15 个字符',
            trigger: 'blur'
          }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          {
            min: 6,
            max: 15,
            message: '长度在 6 到 15 个字符',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created () {

  },
  methods: {
    async login () {
      try {
        const valid = await this.$refs.form.validate()
        console.log(valid)
        if (valid) {
          const res = await login(this.form)
          console.log(res)
          this.$store.commit('user/setUserToken', res.data.token.token)
          this.$router.push('/')
        }
        // console.log(valid)
      } catch (e) {
        console.log(e)
      }
    },
    async getCode (data) {
      const code = await getCode(data)
      console.log(code)
    },
    updataCode () {
      this.form.key = String(new Date().getTime())
      console.log(this.form.key)
    }
  }

}
</script>

<style lang="scss">
.el-input-group__append{
  width: 100px !important;
  height: 100% !important;
  /* background-color:#000 !important; */
  img{
width: 100%;
height: 100%;
  }
 }
.videoContainer{
  position: fixed;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: -100;
}
.login-container .shadow{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  opacity: .3;
  background: #1a1c41;
}
.login-box {
  position: absolute;
  top: 45%;
  left: 45%;
  margin: -180px 0 0 -160px;
  width: 450px;
  height: 467px;
  padding: 36px 40px;
  background: #fff;
  border-radius: 10px;
}
.avatar-box{
  position: relative;
  margin-bottom: 28px;
  text-align: center;
}
img{
  height: 54px;
  border-style: none;
}
.btns {
    width: 100%;
    height: 54px;
    margin-bottom: 14px;
    margin-top: 22px;
    background-color: #e15536;
    border: 0;
    font-size: 18px;
    color: #fff;
    font-weight: 700;
}
.el-input__inner{
  padding-left: 48px;
  height: 50px;
}
.el-input .el-input__clear  {
  line-height: 50px;
  font-size: 20px;
}
.el-input__icon{
  line-height: 50px;
  font-size: 20px;
}
.el-button {
  width: 100%;
  border-radius: 4px;
  background: #fff;
}
span{
    font-size: 18px;
  }
</style>
